define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order_service/index' + location.search,
                    add_url: 'order/order_service/add',
                    edit_url: 'order/order_service/edit',
                    del_url: 'order/order_service/del',
                    multi_url: 'order/order_service/multi',
                    import_url: 'order/order_service/import',
                    table: 'service_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'service.name', title: __('Service.name'), operate: 'LIKE'},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'member.nickname', title: __('下单用户昵称'), operate: 'LIKE'},
                        {field: 'member.realname', title: __('下单用户姓名'), operate: 'LIKE'},
                        {field: 'member.mobile', title: __('下单用户手机号'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('服务老师昵称'), operate: 'LIKE'},
                        {field: 'user.realname', title: __('服务老师姓名'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('服务老师手机号'), operate: 'LIKE'},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"5":__('Status 5')}, formatter: Table.api.formatter.status},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'complete_time', title: __('Complete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons: [
                           {
                                name: 'refund',
                                text: __('退款'),
                                title: __('退款'),
                                classname: 'btn btn-xs btn-danger btn-dialog',
                                icon: 'fa fa-reply',
                                url: 'order/order_service/refund',
                                visible: function(row) {
                                    return row.status == 1; // 已支付状态可以退款
                                },
                                extend: 'data-area=["500px","400px"]'
                            }
                        ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        refund: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
